import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import './styles/nprogress.css'
import store from './store'
const whiteList = ['/login']
router.beforeEach(async(to, from, next) => {
  NProgress.start()
  if (true) {
    if (to.path === '/login') {
      next()
      NProgress.done()
    } else {
      next()
      // const rolesTable = store.getters.roles.map(item => {
      //   return item.ruleCode
      // })
      // const accessRoutes = await store.dispatch('generateRoutes', rolesTable)
      // router.addRoutes(accessRoutes)
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      next(`/login?redirect=${to.path}`)
      NProgress.done()
    }
  }
})
router.afterEach(() => {
  NProgress.done()
})
